<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="">
    <meta http-equiv="x-dns-prefetch-control" content="on">

    <title>订单完成</title>
    <link href="../../css/css.css" rel="stylesheet" type="text/css">
    <script src="../../js/jquery-v1.11.2.min.js"></script>
    <script src="../../js/driver.js"></script>
    <script src="../../js/common.js"></script>
</head>
<body>
<!--二维码弹出-->
<section class="markbg" style="display:none;" id="scanpaydiv">
    <div class="popuparea">
        <div class="order_title">
            <font id="scanType"></font>支付二维码
            <i class="iconfont closeico" onclick="closeScanDiv();">&#xe601;</i>
        </div>
        <div class="p_code_img">
            <img src="../../img/p_code.png" id="scanimage" width="100%" height="100%"/>
        </div>
        <div class="photoitem p15">
            <span class="font14 left">订单总金额:</span>
            <span class="font14 right orange" id="sanpayfee">16540.05元</span>
        </div>
    </div>
</section>
<!--END-->
<section class="bigicon">
    <i class="iconfont">&#xe613;</i>
</section>
<section class="submit_ok_text">
    <span class="oktext">订单完成</span>
</section>
<section class="itemgroup mt10 p15">
    <div class="oneitem">
        <label class="gray">联系人:</label>
        <i class="iconfont rightsmallicon">&#xe6db;</i>
        <label class="right" id="consignName"></label>
    </div>
</section>
<section class="itemgroup mt10 p15" style="display:none;" id="scanpaysection">
	<div class="oneitem" id="scanPay">
		<div class="gray left">支付方式</div>
		<i class="iconfont rightsmallicon">&#xe6db;</i>
		<div class="right" id="paymentTypeName"></div>
	</div>
</section>
<section class="itemgroup mt10 p15 mb80">
    <div class="oneitem">
        <div class="gray left">总计行驶:</div>
        <div class="right"><label class="mr5" id="distance">0</label>公里</div>
    </div>
    <div class="oneitem">
        <div class="gray left">起步价(含<span id="exceedDistance"></span>公里内):</div>
        <div class="right"><label class="red mr5" id="startFee">0</label>元</div>
    </div>
    <div class="oneitem" style="display:none;">
        <div class="gray left">超里程费(超出<span id="exceedDistance1"></span>公里):</div>
        <div class="right"><label class="red mr5" id="exceedFee">0</label>元</div>
    </div>
    <div class="oneitem">
        <div class="gray left">运价:</div>
        <div class="right"><label class="red mr5" id="exceedPrice">3.5</label>元/公里</div>
    </div>
    <div class="oneitem">
        <div class="gray left">起运时间:</div>
        <div class="right"><label class="mr5" id="placeDate">00:00</label></div>
    </div>
    <div class="oneitem">
        <div class="gray left">到达时间:</div>
        <div class="right"><label class="mr5" id="unloadDate">00:00</label></div>
    </div>
    <div class="oneitem">
        <div class="gray left">等候时间:</div>
        <div class="right"><label class="mr5" id="waitTime">00:00:00</label></div>
    </div>
    
    <div class="oneitem">
        <div class="gray left">特殊需求(搬运):</div>
        <div class="right"><label class="red mr5" id="specialFee">0</label>元</div>
    </div>
    <div class="oneitem" style="display:none;">
        <div class="gray left">装/卸货等待费用:</div>
        <div class="right"><label class="red mr5" id="loadFee">0</label>元</div>
    </div>
    <div class="oneitem" style="display:none;">
        <div class="gray left">行驶途中等待费用:</div>
        <div class="right"><label class="red mr5" id="lowSpeedFee">0</label>元</div>
    </div>
    <div class="oneitem">
        <div class="gray left">路桥费:</div>
        <div class="right"><label class="red mr5" id="hignRoadFee">0</label>元</div>
    </div>
</section>
<section class="detialbottom">
    <button type="button" class="right btn addcert_det" id="tellCustPay">通知货主付款</button>
    <a href="#" onclick="gotoChangePrice();">
        <button class="right btnwhite addcert_det">修改费用</button>
    </a>
    <div class="cart_clear2 ml15">
        <span class="font12">总计向客户索取费用:</span>
        <span class="red font16" id="totalFee">￥0.00</span>
    </div>
</section>
<script type="text/javascript">
    $(function () {
        //token验证
        checkDriverToken();
    });
    var consignMobile = "";
    var waybillSource = "";
    var waybillId = "";
    var paymentType = "";
    var totalfeeall = "";
    $(document).ready(function () {
        waybillId = GetArgsFromHref("waybillId");
        setCookie('driverWaybillId', waybillId);
        paymentType = GetArgsFromHref("paymentType");
        if(!paymentType)paymentType="80";
        var url = _global.serverHost + "/driver/ok_bid.htm";
        var data = {waybillId: waybillId,"paymentType": paymentType};
        _callAjaxRequest(url, data, startBidBack);

//        $("#hignRoadFee").html(getCookie('driverHignRoadFee'));
//        $("#specialFee").html(getCookie('driverSpecialFee'));

        function startBidBack(data) {
        		//if(data.waybill.consignMobile=='10000000000' || data.waybill.waybillSource=='30'){
        			//$("#tellCustPay").html("完成订单");
      			if(paymentType!='80'){
      				$("#tellCustPay").html("开始付款");
      			}else{
      				$("#tellCustPay").html("完成订单");
      			}
      			$("#scanpaysection").css('display','block'); 
      			$("#scanPay").attr("onclick", "changePay('"+waybillId+"')");
      			$("#paymentTypeName").html(data.paymentTypeName);
        		//}
            $("#consignName").html((data.waybill.consignName == "" || data.waybill.consignName == null) ? data.waybill.consignMobile : data.waybill.consignName);
            $("#distance").html(data.waybill.distance);
            $("#startFee").html(data.waybill.startFee);
            $("#exceedFee").html(data.waybill.exceedFee);
            $("#specialFee").html(data.waybill.specialFee);
            $("#adjustFee").html(data.waybill.adjustFee);
            $("#loadFee").html((data.waybill.loadFee==null?0:data.waybill.loadFee)*1.0+(data.waybill.unloadFee==null?0:data.waybill.unloadFee)*1.0 );
            $("#lowSpeedFee").html(data.waybill.lowSpeedFee);
            $("#hignRoadFee").html(data.waybill.hignRoadFee);
            $("#totalFee").html("￥" + (data.waybill.totalFee==null?0:data.waybill.totalFee));
            totalfeeall = data.waybill.totalFee==null?0:data.waybill.totalFee;
            $("#exceedDistance").html(data.initDistance);//data.exceedDistance
            if (parseInt(parseFloat(data.waybill.distance) * 10) > parseInt(parseFloat(data.initDistance) * 10)) {
                var exceedDistance2 = (parseInt(parseFloat(data.waybill.distance) * 10) - parseInt(parseFloat(data.initDistance) * 10)) / 10.0;
                $("#exceedDistance1").html(exceedDistance2);
            }
            $("#exceedPrice").html(data.vehiclePrice.pv3);
            $("#placeDate").html(data.waybill.placeDate);
            $("#unloadDate").html(data.waybill.unloadDate);
            var ln_waitTime=data.waybill.unloadTime+data.waybill.lowSpeedTime;
            if(data.waybill.loadTime>600){//超过10分钟=600秒
            	ln_waitTime=ln_waitTime+data.waybill.loadTime-600;
            }
            $("#waitTime").html(Number(ln_waitTime).formatTime());
            consignMobile = data.waybill.consignMobile;
            waybillSource = data.waybill.waybillSource;
        }

        $("#tellCustPay").attr("onclick", "tellCustPay()");
    });
    
    function tellCustPay() {
    		//if(consignMobile=='10000000000' || waybillSource=='30'){
        			//在这里实现现金付款的流程
        			if(paymentType=='80'){
        			var update = confirm('您确定客户已经完成现金支付？');
	        		if(update){
	        				$.ajax({
	                url: _global.serverHost + '/wxpay/cashpay.htm',// 跳转到 action
	                data: {waybillId: waybillId},
	                type: 'post',
	                cache: false,
	                dataType: 'json',
	                success: function (data) {
	                    //返回的数据为一个form表单和提交该form的script,通过提交该表单（提交到支付宝，提交的数据等一系列内容已经全部包含在后台返回的data数据中，我们只需要运行data中的script即可）
	                    if (data.code == 1) {
	                    	//点击“立即支付”，到达左图中步骤7之后，调用Native定义的JS方法startWeiChatPay(nonce_str,sign,prepayid)
	                    	//随机字符串          nonce_str,签名                sign,预支付交易会话ID    prepayid"
	                        window.location.href = "../order/order_list.html";
	                    } else {
	                        alert("支付没有成功：" + data.msg);
	                    }
	                },
	                error: function () {
	                    alert("支付发生异常，请重试！");
	                }
	            });
	        		}else{
        					return false;
	          	}
	          }else if(paymentType=='10'){
	          	//微信扫码支付
	          	$.ajax({
	                url: _global.serverHost + '/wxpay/scanpay.htm',// 跳转到 action
	                data: {waybillId: waybillId},
	                type: 'post',
	                cache: false,
	                dataType: 'json',
	                success: function (data) {
	                    //返回的数据为一个form表单和提交该form的script,通过提交该表单（提交到支付宝，提交的数据等一系列内容已经全部包含在后台返回的data数据中，我们只需要运行data中的script即可）
	                    if (data.code == 1) {
	                    	//点击“立即支付”，到达左图中步骤7之后，调用Native定义的JS方法startWeiChatPay(nonce_str,sign,prepayid)
	                    	//随机字符串          nonce_str,签名                sign,预支付交易会话ID    prepayid"
	                        //alert(data.wxscanurl);
	                        $("#scanpaydiv").css('display','block'); 
	                        $("#scanimage").attr("src", data.wxscanurl);
	                        var payid = data.out_trade_no;
	                        $("#sanpayfee").html(totalfeeall+"元");
	                        $("#scanType").html("微信");
	                        console.log("out_trade_no="+payid);
	                        checkService(payid);
	                    } else {
	                        alert("支付没有成功：" + data.msg);
	                    }
	                },
	                error: function () {
	                    alert("支付发生异常，请重试！");
	                }
	            });
	          }else if(paymentType=='20'){
	          	//支付宝扫码支付
	          	$.ajax({
	                url: _global.serverHost + '/alipay/scan_pay.htm',// 跳转到 action
	                data: {waybillId: waybillId},
	                type: 'post',
	                cache: false,
	                dataType: 'json',
	                success: function (data) {
	                    //返回的数据为一个form表单和提交该form的script,通过提交该表单（提交到支付宝，提交的数据等一系列内容已经全部包含在后台返回的data数据中，我们只需要运行data中的script即可）
	                    if (data.code == 1) {
	                    	//点击“立即支付”，到达左图中步骤7之后，调用Native定义的JS方法startWeiChatPay(nonce_str,sign,prepayid)
	                    	//随机字符串          nonce_str,签名                sign,预支付交易会话ID    prepayid"
	                        //alert(data.wxscanurl);
	                        $("#scanpaydiv").css('display','block'); 
	                        $("#scanimage").attr("src", data.aliscanurl);
	                        var payid = data.out_trade_no;
	                        $("#sanpayfee").html(totalfeeall+"元");
	                        $("#scanType").html("支付宝");
	                        console.log("out_trade_no="+payid);
	                        checkService(payid);
	                    } else {
	                        alert("支付没有成功：" + data.msg);
	                    }
	                },
	                error: function () {
	                    alert("支付发生异常，请重试！");
	                }
	            });
	          }
        //}else{
        //		window.location.href = "../order/order_list.html";
        //}
    }
    
    function closeScanDiv(){
    		$("#scanpaydiv").css('display','none'); 
    }
    
    function checkService(payid){
    		console.log("start check result");
				try{
        	$.ajax({
	                url: _global.serverHost + '/wxpay/scanpayverify.htm',// 跳转到 action
	                data: {payid: payid},
	                type: 'post',
	                cache: false,
	                dataType: 'json',
	                success: function (data) {
	                    //返回的数据为一个form表单和提交该form的script,通过提交该表单（提交到支付宝，提交的数据等一系列内容已经全部包含在后台返回的data数据中，我们只需要运行data中的script即可）
	                    if (data.code == 1) {
	                    	//点击“立即支付”，到达左图中步骤7之后，调用Native定义的JS方法startWeiChatPay(nonce_str,sign,prepayid)
	                    	//随机字符串          nonce_str,签名                sign,预支付交易会话ID    prepayid"
	                    		if(data.payresult == 1){
	                    			alert("付款成功!");
	                        	window.location.href = "../order/order_list.html";
	                      	}
	                    } else {
	                        alert("支付没有成功：" + data.msg);
	                    }
	                },
	                error: function () {
	                    alert("支付发生异常，请重试！");
	                }
	            });
      	}catch(e){}
　     setTimeout("checkService('"+payid+"')", 2000);
   	} 

    function gotoChangePrice() {
        setCookie('driverHignRoadFee', $("#hignRoadFee").html());
        setCookie('driverSpecialFee', $("#specialFee").html());
        window.location.href = "./change_price.html";
    }
    
    function changePay(waybillId) {
        // window.location.href="${pageContext.request.contextPath}/consignerOrderManger/selectPay.htm?paymentType=${paymentType}&waybillId="+waybillId;
        window.location.href = "select_pay.html?waybillId=" + waybillId + "&paymentType=80";
    }
</script>
</body>
</html>